<template>
  <div>
    <el-dialog :title="title" :visible.sync="showDialog" :before-close="dialogFormVisible" width="95%" style="margin-top:-5%;margin-left:10%; ">
      <el-form :model="form" :rules="rules" ref="form">
        <el-row :gutter="20">
          <el-col :span="6">
            <el-form-item size="small" class="Dh_item" label="线路" :label-width="formLabelWidth" prop="route_id">
              <el-select v-model="form.route_id" placeholder="请选择" @change="getLined" :disabled="redact">
                <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value"> </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item size="small" class="Dh_item" label="日期" :label-width="formLabelWidth" prop="bus_date">
              <el-date-picker v-model="form.bus_date" type="date" placeholder="选择日期" value-format="yyyy-MM-dd" format="yyyy-MM-dd" @change="Times"></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item size="small" class="Dh_item" label="班次号" :label-width="formLabelWidth" prop="bus_id">
              <!-- <el-select v-if="add" v-model="form.bus_id" placeholder="请选择" @change="getPrice">
                <el-option v-for="item in classesList" :key="item.busNum" :label="item.busNum" :value="item.busNum"> </el-option>
              </el-select> -->
              <el-input size="small" v-model="form.bus_id" @blur="getPrice"></el-input>

              <!-- <el-input v-if="classes" size="small" v-model="form.bus_id"></el-input> -->
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item size="small" class="Dh_item" label="所属车站" :label-width="formLabelWidth" prop="station_id">
              <el-select v-model="form.station_id" placeholder="请选择" @change="getFormId">
                <el-option v-for="item in stationArr" :key="item.value" :label="item.label" :value="item.value"> </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row :gutter="20">
          <el-col :span="6">
            <el-form-item size="small" class="Dh_item" label="运营类别" :label-width="formLabelWidth" prop="work_type">
              <el-select v-model="form.work_type" placeholder="请选择">
                <el-option label="单营" value="1"></el-option>
                <el-option label="共营" value="2"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item size="small" class="Dh_item" label="运营方式" :label-width="formLabelWidth" prop="work_way">
              <el-select v-model="form.work_way" placeholder="请选择">
                <el-option label="直达" value="1"></el-option>
                <el-option label="普通" value="2"></el-option>
                <el-option label="公交" value="3"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item size="small" class="Dh_item" label="区域类型" :label-width="formLabelWidth" prop="district_type">
              <el-select v-model="form.district_type" placeholder="请选择" :disabled="redact">
                <el-option label="县内班线" value="0"></el-option>
                <el-option label="县际班线" value="1"></el-option>
                <el-option label="市际班线" value="2"></el-option>
                <el-option label="省际班线" value="3"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item size="small" class="Dh_item" label="车次类型" :label-width="formLabelWidth" prop="bus_type">
              <el-select v-model="form.bus_type" placeholder="请选择">
                <el-option label="固定" value="0"></el-option>
                <el-option label="流水" value="1"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row :gutter="20">
          <el-col :span="6">
            <el-form-item size="small" class="Dh_item" label="发车时间" :label-width="formLabelWidth" prop="start_time">
              <el-time-picker v-model="form.start_time" placeholder="任意时间点" format="HH:mm" value-format="HH:mm"> </el-time-picker>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item size="small" class="Dh_item" label="检票口" :label-width="formLabelWidth" prop="check_gate">
              <el-input size="small" v-model="form.check_gate"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item size="small" class="Dh_item" label="发车位" :label-width="formLabelWidth" prop="parking_space">
              <el-input size="small" v-model="form.parking_space"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item size="small" class="Dh_item" label="候车厅" :label-width="formLabelWidth" prop="waitting_room">
              <el-input size="small" v-model="form.waitting_room"></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row :gutter="20">
          <el-col :span="6">
            <el-form-item size="small" class="Dh_item" label="滚动车次循环时间" :label-width="formLabelWidth" prop="scrollbus_check_time">
              <el-input size="small" v-model="form.scrollbus_check_time"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item size="small" class="Dh_item" label="车辆编号" :label-width="formLabelWidth" prop="vehicle_id">
              <el-select v-model="form.vehicle_id" placeholder="请选择">
                <el-option v-for="item in vehicleInfoList" :key="item.value" :label="item.label" :value="item.value"> </el-option>
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="6">
            <el-form-item size="small" class="Dh_item" label="车属公司" :label-width="formLabelWidth" prop="transport_company_id">
              <el-select v-model="form.transport_company_id" placeholder="请选择">
                <el-option v-for="item in companyList" :key="item.value" :label="item.label" :value="item.value"> </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item size="small" class="Dh_item" label="是否本站专属车次" :label-width="formLabelWidth" prop="is_proprietary">
              <el-select v-model="form.is_proprietary" placeholder="请选择">
                <el-option label="是" :value="true"></el-option>
                <el-option label="否" :value="false"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row :gutter="20">
          <el-col :span="6">
            <el-form-item size="small" class="Dh_item" label="是否加班" :label-width="formLabelWidth" prop="is_overtime">
              <el-select v-model="form.is_overtime" placeholder="请选择">
                <el-option label="是" :value="true"></el-option>
                <el-option label="否" :value="false"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item size="small" class="Dh_item" label="是否报道后售票" :label-width="formLabelWidth" prop="is_saleafterreport">
              <el-select v-model="form.is_saleafterreport" placeholder="请选择">
                <el-option label="是" :value="true"></el-option>
                <el-option label="否" :value="false"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item size="small" class="Dh_item" label="是否实名制" :label-width="formLabelWidth" prop="is_realname">
              <el-select v-model="form.is_realname" placeholder="请选择">
                <el-option label="是" :value="true"></el-option>
                <el-option label="否" :value="false"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item size="small" class="Dh_item" label="座位数" :label-width="formLabelWidth" prop="total_seat">
              <el-input size="small" v-model="form.total_seat"></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row :gutter="20">
          <el-col :span="6">
            <el-form-item size="small" class="Dh_item" label="已售出座位数" :label-width="formLabelWidth" prop="sold_seat">
              <el-input size="small" v-model="form.sold_seat"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item size="small" class="Dh_item" label="携童数" :label-width="formLabelWidth" prop="take_child">
              <el-input size="small" v-model="form.take_child"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item size="small" class="Dh_item" label="车次状态" :label-width="formLabelWidth" prop="status">
              <el-select v-model="form.status" placeholder="请选择">
                <el-option label="开" :value="true"></el-option>
                <el-option label="停" :value="false"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item size="small" class="Dh_item" label="互售张数" :label-width="formLabelWidth" prop="interlink_quantity">
              <el-input size="small" v-model="form.interlink_quantity"></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row :gutter="20">
          <el-col :span="6">
            <el-form-item size="small" class="Dh_item" label="互联网张数" :label-width="formLabelWidth" prop="internet_quantity">
              <el-input size="small" v-model="form.internet_quantity"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item size="small" class="Dh_item" label="备注" :label-width="formLabelWidth">
              <el-input size="small" v-model="form.remark"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div class="btn" style="text-align: center;">
        <el-button type="primary" @click="updates('form')" class="update" v-if="renewal">更新</el-button>
        <el-button type="primary" @click="increased('form')" class="update" v-if="newly">新增</el-button>
        <el-button type="warning" @click="dialogFormVisible" class="close">关闭 </el-button>
      </div>
      <!-- 环境车次票价 -->
      <div class="table">
        <p style="color:red;">备注：如果状态是<span style="color:red">未启用</span>，需要在<span style="color:#03a9f4">计划车列表 —> 该线路编辑 —> 车次票价</span>中设置启用后才能编辑！</p>
        <el-table :data="sectionArr" height="310" border :header-cell-style="{ 'text-align': 'center', background: '#3073a9', color: '#fff' }" :cell-style="{ 'text-align': 'center' }" style="width: 100%;text-align: center;margin-top:2%;" :row-class-name="tableRowClassName" :default-sort="{ prop: 'bus_date', order: 'descending' }">
          <el-table-column prop="bus_date" sortable label="日期" width="150px">
            <template slot-scope="scope">
              <el-input class="Dh_frame" size="mini" v-model="times" @change="getCount(scope.row)" :disabled="true"> </el-input>
            </template>
          </el-table-column>
          <el-table-column prop="bus_id" label="班次号" width="100px">
            <template slot-scope="scope">
              <el-input class="Dh_frame" size="mini" v-model="form.bus_id" @change="getCount(scope.row)" :disabled="true"> </el-input>
            </template>
          </el-table-column>

          <el-table-column prop="subordinate_id" label="所属车站" width="150px">
            <el-select v-model="form.station_id" placeholder="请选择" :disabled="true">
              <el-option v-for="item in stationArr" :key="item.value" :label="item.label" :value="item.value"> </el-option>
            </el-select>
          </el-table-column>
          <el-table-column label="站点" width="150px">
            <template slot-scope="scope">
              <el-select v-model="scope.row.stationId" placeholder="" size="mini" class="Dh_frame" :disabled="scope.row.sectionPrice.id == null">
                <el-option v-for="(item, index) in target" :key="index" :label="item.name" :value="item.id"> </el-option>
              </el-select>
            </template>
          </el-table-column>
          <el-table-column label="状态" width="100px">
            <template prop="id" slot-scope="scope">
              <!-- <el-input class="Dh_frame" size="mini" v-model="scope.row" :disabled="true"> </el-input> -->
              <span :style="{color: scope.row.sectionPrice.id ? '#03a9f4' : 'red'}">{{scope.row.sectionPrice.id ? '已启用' : '未启用'}}</span>
            </template>
          </el-table-column>
          <el-table-column prop="seat_type" label="座位类型" width="100px">
            <template slot-scope="scope">
              <el-select v-model="scope.row.sectionPrice.seatType" placeholder="" size="mini" :disabled="scope.row.sectionPrice.id == null">
                <el-option v-for="item in seat_type" :key="item.value" :label="item.label" :value="item.value"> </el-option>
              </el-select>
            </template>
          </el-table-column>
          <el-table-column prop="ticket_type" label="票种" width="100px">
            <template slot-scope="scope">
              <el-select v-model="scope.row.sectionPrice.ticketType" placeholder="" size="mini" :disabled="scope.row.sectionPrice.id == null">
                <el-option v-for="item in bus_price" :key="item.value" :label="item.label" :value="item.value"> </el-option>
              </el-select>
            </template>
          </el-table-column>
          <el-table-column prop="station_serial" label="序号">
            <template slot-scope="scope">
              <el-input size="mini" v-model="scope.row.sectionPrice.stationSerial" :disabled="scope.row.sectionPrice.id == null"> </el-input>
            </template>
          </el-table-column>
          <el-table-column prop="mileage" label="里程"> </el-table-column>
          <el-table-column prop="total_price  " label="总票价">
            <template slot-scope="scope">
              <span>{{Number(scope.row.sectionPrice.baseCarriage) + Number(scope.row.sectionPrice.stationServiceFee) + 
                Number(scope.row.sectionPrice.fuelAddFee) + Number(scope.row.sectionPrice.computeFee) + Number(scope.row.sectionPrice.coolairFee) + 
                Number(scope.row.sectionPrice.healthFee) + Number(scope.row.sectionPrice.otherFee)}}</span>
              <!-- <el-input size="mini" v-model="scope.row.total_price"> </el-input> -->
            </template>
          </el-table-column>
          <el-table-column prop="base_carriage" label="运价">
            <template slot-scope="scope">
              <el-input size="mini" v-model="scope.row.sectionPrice.baseCarriage" :disabled="scope.row.sectionPrice.id == null"> </el-input>
            </template>
          </el-table-column>
          <el-table-column prop="station_servicefee" label="站务费">
            <template slot-scope="scope">
              <el-input size="mini" v-model="scope.row.sectionPrice.stationServiceFee" :disabled="scope.row.sectionPrice.id == null"> </el-input>
            </template>
          </el-table-column>
          <el-table-column prop="fuel_add_fee" label="燃油附加费" width="100px">
            <template slot-scope="scope">
              <el-input size="mini" v-model="scope.row.sectionPrice.fuelAddFee" :disabled="scope.row.sectionPrice.id == null"> </el-input>
            </template>
          </el-table-column>
          <el-table-column prop="compute_fee" label="微机费">
            <template slot-scope="scope">
              <el-input size="mini" v-model="scope.row.sectionPrice.computeFee" :disabled="scope.row.sectionPrice.id == null"> </el-input>
            </template>
          </el-table-column>
          <el-table-column prop="coolair_fee" label="空调费">
            <template slot-scope="scope">
              <el-input size="mini" v-model="scope.row.sectionPrice.coolairFee" :disabled="scope.row.sectionPrice.id == null"> </el-input>
            </template>
          </el-table-column>
          <el-table-column prop="health_fee" label="卫生费">
            <template slot-scope="scope">
              <el-input size="mini" v-model="scope.row.sectionPrice.healthFee" :disabled="scope.row.sectionPrice.id == null"> </el-input>
            </template>
          </el-table-column>
          <el-table-column prop="other_fee" label="其他费">
            <template slot-scope="scope">
              <el-input size="mini" v-model="scope.row.sectionPrice.otherFee" :disabled="scope.row.sectionPrice.id == null"> </el-input>
            </template>
          </el-table-column>
          <el-table-column prop="toplimit_price" label="上限票价">
            <template slot-scope="scope">
              <el-input size="mini" v-model="scope.row.sectionPrice.topLimitPrice" :disabled="scope.row.sectionPrice.id == null"> </el-input>
            </template>
          </el-table-column>
          <el-table-column prop="lowerlimit_price" label="下限票价">
            <template slot-scope="scope">
              <el-input size="mini" v-model="scope.row.sectionPrice.lowerLimitPrice" :disabled="scope.row.sectionPrice.id == null"> </el-input>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </el-dialog>
  </div>
</template>
<script>
const busApi = $api.dispatch.bus_Info
const sectionApi = $api.dispatch.route_Info
const api = $api.dispatch.env_bus_Info
// /api/dispatch/common/querylinedetailinfo
// /api/dispatch/common/queryrunlinedetailinfo
export default {
  props: ['show', 'busData', 'isAdd', 'formInline', 'copy'],
  data() {
    return {
      title: '',
      showDialog: false,
      form: {
        district_type: '',
        bus_date: '',
        bus_id: '',
        station_id: '',
        route_id: '',
        work_type: '',
        work_way: '',
        bus_type: '',
        start_time: '',
        check_gate: '',
        parking_space: '',
        waitting_room: '',
        scrollbus_check_time: '',
        vehicle_id: '',
        transport_company_id: '',
        is_proprietary: '',
        is_overtime: '',
        is_saleafterreport: false,
        is_realname: true,
        total_seat: '',
        sold_seat: '',
        take_child: '',
        status: true,
        interlink_quantity: '',
        internet_quantity: '',
        remark: '',
      },
      lineId: '', //线路ID
      rules: {
        route_id: [{ required: true, message: '请选择线路', trigger: 'change' }],
        bus_date: [{ required: true, message: '请选择日期', trigger: 'change' }],
        bus_id: [{ required: true, message: '请选择班次号', trigger: 'change' }],
        station_id: [{ required: true, message: '请选择所属车站', trigger: 'change' }],
        work_type: [{ required: true, message: '请选择运营类别', trigger: 'change' }],
        work_way: [{ required: true, message: '请选择运营方式', trigger: 'change' }],
        district_type: [{ required: true, message: '请选择区域类别', trigger: 'change' }],
        bus_type: [{ required: true, message: '请选择车次类型', trigger: 'change' }],
        start_time: [{ required: true, message: '请选择发车时间', trigger: 'change' }],
        check_gate: [{ required: true, message: '请输入检票口', trigger: 'change' }],
        parking_space: [{ required: true, message: '请输入发车位', trigger: 'blur' }],
        waitting_room: [{ required: true, message: '请输入候车厅', trigger: 'blur' }],
        scrollbus_check_time: [{ required: true, message: '请输入循环时间', trigger: 'blur' }],
        vehicle_id: [{ required: true, message: '请选择车辆编号', trigger: 'change' }],
        transport_company_id: [{ required: true, message: '请选择车属公司', trigger: 'change' }],
        is_proprietary: [{ required: true, message: '请选择是否专属', trigger: 'change' }],
        is_overtime: [{ required: true, message: '请选择是否加班号', trigger: 'change' }],
        is_saleafterreport: [{ required: true, message: '请选择是否报道后售票', trigger: 'change' }],
        is_realname: [{ required: true, message: '请选择是否实名制', trigger: 'change' }],
        total_seat: [{ required: true, message: '请输入座位数', trigger: 'blur' }],
        sold_seat: [{ required: true, message: '请输入已售座位数', trigger: 'blur' }],
        take_child: [{ required: true, message: '请输入携童数', trigger: 'blur' }],
        status: [{ required: true, message: '请选择车次状态', trigger: 'change' }],
        interlink_quantity: [{ required: true, message: '请输入互售张数', trigger: 'change' }],
        internet_quantity: [{ required: true, message: '请输入互联网张数', trigger: 'change' }],
      },
      formLabelWidth: '145px',
      options: [],
      renewal: false,
      newly: false,
      stationArr: [],
      classesList: [],
      // dialog: false,
      sectionArr: [],
      seat_type: [],
      bus_price: [],
      target: [],
      companyList: [],
      vehicleInfoList: [],
      redact: false,
      times: '',
      add: false,
      classes: false,
    }
  },
  mounted() {
    this.showDialog = this.show
    if (this.isAdd == false) {
      if (this.copy == true) {
        this.classes = true
        this.add = false
        this.title = '复制环境车次'
        this.redact = true
        this.form.bus_date = this.formInline.busDate
        this.form.bus_type = this.formInline.busType
        this.form.check_gate = this.formInline.checkGate
        this.form.district_type = this.formInline.districtType
        this.form.is_proprietary = this.formInline.isProprietart
        this.form.is_realname = this.formInline.isRealName
        this.form.is_saleafterreport = this.formInline.isSaleAfterReport
        this.form.route_id = this.formInline.lineId
        this.form.parking_space = this.formInline.parkingSpace
        this.form.sold_seat = this.formInline.soldSeat
        this.form.start_time = this.formInline.startTime
        this.form.station_id = this.formInline.stationId //所属车站逻辑
        this.form.status = this.formInline.status
        this.form.total_seat = this.formInline.totalSeat
        this.form.transport_company_id = this.formInline.transprotCompanyId
        this.form.vehicle_id = this.formInline.vehicleId
        this.form.waitting_room = this.formInline.waittingRoom
        this.form.work_type = this.formInline.workType
        this.form.work_way = this.formInline.workWay
        this.form.interlink_quantity = this.formInline.interlinkQuantity
        this.form.internet_quantity = this.formInline.internetQuantity
        this.form.take_child = this.formInline.childSeat
        this.form.remark = this.formInline.remark
        this.form.scrollbus_check_time = this.formInline.scrollBusCheckTime
        this.form.is_overtime = this.formInline.isOvertime
        //复制班次 环境票价
        this.times = this.formatDate(this.formInline.busDate)
        this.getHData(this.formInline.lineId, this.formInline.busNum)

        // busApi.querylinedetailinfo({ lineId: this.formInline.lineId, busId: this.formInline.busNum }).then((res) => {
        //   console.log(res)
        //   this.sectionArr = res.lineSections
        // })
      } else {
        this.getDetails()
        this.add = true
        this.classes = false
        this.title = '新增环境车次'
      }
      this.newly = true
    } else {
      this.add = true
      this.times = this.formatDate(this.busData.busDate)
      this.redact = this.isAdd
      this.renewal = true
      this.getDetails()
      this.title = '编辑环境车次'
    }
    this.getUserStation()
    this.lineList()
    this.organization()
    this.getTicketType()
    this.getSeatType()
    this.getClasses()
    this.getTarget()
    this.getCompany()
    this.getVehicleInfo()
  },
  methods: {
    //获取票价
    getHData(lineId, busNum) {
      api.queryrunlinedetailinfo({ lineId: lineId, busId: busNum }).then((o) => {
        this.sectionArr = o.lineSections
      })
    },
    getFormId(val) {
      this.form.station_id = value
    },
    // 获取用户当前汽车站
    getUserStation(data) {
      if (JSON.parse(localStorage.getItem('userMsg')).userName == 'admin') {
        // that.form.station_id = data.value
        this.stationArr = data
        return
      }
      sectionApi.getstartstation().then((res) => {
        const that = this
        if (data) {
          data.forEach((e) => {
            if (e.label == res[0].name) {
              that.form.station_id = e.value
              that.stationArr = [e]
            }
          })
        }
      })
    },

    // 隔行变色
    tableRowClassName({ rowIndex }) {
      if (rowIndex % 2 == 1) {
        return 'warning-row'
      } else {
        return 'success-row'
      }
    },
    dialogFormVisible() {
      this.showDialog = false
      this.$emit('hide')
    },
    // 获取座位类型
    getSeatType() {
      busApi.sateQuery().then((res) => {
        var arr = res.rows.map((item) => {
          return { value: item.id, label: item.seat_type_name }
        })
        this.seat_type = arr
      })
    },
    //获取车票类型
    getTicketType() {
      busApi.ticketQuery().then((res) => {
        var arr = res.rows.map((item) => {
          return { value: item.id, label: item.ticekt_type_name }
        })
        this.bus_price = arr
      })
    },
    //获取站点
    getTarget() {
      api.tartgetInfoQuery().then((res) => {
        this.target = res.rows
      })
    },
    // 获取线路编码
    lineList() {
      busApi.routeQuery().then((res) => {
        var arr = res.rows.map((item) => {
          return { value: item.id, label: item.route_name }
        })
        this.options = arr
      })
    },
    //获取线路信息
    getLined(k) {
      this.lineId = k
      busApi.querylinedetailinfo({ lineId: k }).then((res) => {
        this.form.district_type = res.districtType
      })
    },
    //根据路线和班次获取票价
    getPrice(k) {
      if (this.title == '复制环境车次') {
        return
      }
      busApi.querylinedetailinfo({ lineId: this.form.route_id, busId: this.form.bus_id }).then((res) => {
        if (res) {
          this.sectionArr = res.lineSections
          this.form.district_type = res.districtType
        }
      })
    },
    // 获取所属车站
    organization() {
      sectionApi.organizationQuery().then((res) => {
        var arr = res.rows.map((item) => {
          return { value: item.code, label: item.name }
        })
        this.getUserStation(arr)
      })
    },
    //查询车次编号
    getVehicleInfo() {
      api.vehicleQuery().then((res) => {
        var arr = res.rows.map((item) => {
          return { value: item.id, label: item.license_no }
        })
        this.vehicleInfoList = arr
      })
    },
    // 查询所属车站
    getCompany() {
      api.companyQuery().then((res) => {
        var arr = res.rows.map((item) => {
          return { value: item.id, label: item.company_full_name }
        })
        this.companyList = arr
      })
    },
    // 获取班次号seatType
    getClasses() {
      api.querybusinfoforselect().then((res) => {
        this.classesList = res
        // const that = this
        // if (this.isAdd == true) {
        // let obj = {}
        // obj.busNum = this.classesList.find((item) => {
        // return item.id === that.busData.busNum
        // })
        // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        // api.envBusPriceQuery({ bus_id: obj.busNum }).then((res) => {
        //   res.rows.forEach((e) => {
        //     e.seatType = e.seat_type
        //   })
        //   this.sectionArr = res.rows
        // })
        // }
      })
    },
    //获取编辑详情
    getDetails() {
      api.queryrunbusinfodetail({ runBusId: this.busData.id }).then((res) => {
        //获取票价
        this.getHData(res.lineId, res.busNum)
        // api.queryrunlinedetailinfo({ busId: res.busNum, lineId: res.lineId }).then((o) => {
        //   this.sectionArr = o.lineSections
        // })
        this.form.bus_date = res.busDate
        this.form.bus_id = res.busNum
        this.form.bus_type = res.busType
        this.form.check_gate = res.checkGate
        this.form.district_type = res.districtType
        this.form.is_proprietary = res.isProprietart
        this.form.is_realname = res.isRealName
        this.form.is_saleafterreport = res.isSaleAfterReport
        this.form.route_id = res.lineId
        this.form.parking_space = res.parkingSpace
        this.form.sold_seat = res.soldSeat
        this.form.start_time = res.startTime
        this.form.station_id = res.stationId //所属车站
        this.form.status = res.status
        this.form.total_seat = res.totalSeat
        this.form.transport_company_id = res.transprotCompanyId
        this.form.vehicle_id = res.vehicleId
        this.form.waitting_room = res.waittingRoom
        this.form.work_type = res.workType
        this.form.work_way = res.workWay
        this.form.interlink_quantity = res.interlinkQuantity
        this.form.internet_quantity = res.internetQuantity
        this.form.take_child = this.formInline.childSeat
        this.form.remark = this.formInline.remark
        this.form.scrollbus_check_time = this.formInline.scrollBusCheckTime
        this.form.is_overtime = this.formInline.isOvertime
      })
    },
    // 编辑
    updates(formName) {
      var priceList = []
      for (var i = 0; i < this.sectionArr.length; i++) {
        priceList.push(this.sectionArr[i].sectionPrice)
      }

      var arry = []
      priceList.map((item, i) => {
        arry.push(Object.assign({}, item, { station_serial_no: '1', bus_id: this.form.bus_id, station_id: this.sectionArr[i].stationId }))
      })
      var priceArry = arry.map((s) => {
        return {
          id: s.id,
          bus_id: s.bus_id,
          // subordinate_id: s.stationId,
          subordinate_id: this.form.station_id,
          // 目的站点ID
          station_id: s.station_id,
          ticket_type: s.ticketType,
          vehicle_type: s.vehicleType,
          seat_type: s.seatType,
          station_serial_no: s.station_serial_no,
          total_price: s.total_price,
          base_carriage: s.baseCarriage,
          mileage: s.mileage ? s.mileage : 0,
          station_servicefee: s.stationServiceFee,
          fuel_add_fee: s.fuelAddFee,
          compute_fee: s.computeFee,
          coolair_fee: s.coolairFee,
          health_fee: s.healthFee,
          other_fee: s.otherFee,
          toplimit_price: s.topLimitPrice,
          lowerlimit_price: s.lowerLimitPrice,
        }
      })
      this.$refs[formName].validate((valid) => {
        if (valid) {
          // this.increased(formName)
          this.form['id'] = this.busData.id
          api.modifyrunbus({ envBusInfo: this.form, envBusPrices: priceArry }).then((res) => {
            this.$message({
              message: '编辑成功',
              type: 'success',
            })
            this.$emit('hide', true)
            this.showDialog = false
            this.$emit('hide')
          })
        } else {
          this.$message({
            message: '请把内容填写完整',
            type: 'warning',
          })
          return false
        }
      })
    },
    // 新增环境车次
    increased(formName) {
      var priceList = []
      for (var i = 0; i < this.sectionArr.length; i++) {
        priceList.push(this.sectionArr[i].sectionPrice)
      }
      var arry = []
      priceList.map((item, i) => {
        arry.push(Object.assign({}, item, { bus_date: this.times, station_serial_no: '1', bus_id: this.form.bus_id, station_id: this.sectionArr[i].stationId }))
      })
      var priceArry = arry.map((s) => {
        return {
          bus_date: s.bus_date,
          bus_id: s.bus_id,
          // subordinate_id: s.stationId,
          subordinate_id: this.form.station_id,
          station_id: s.station_id,
          seat_type: s.seatType,
          ticket_type: s.ticketType,
          station_serial_no: s.station_serial_no,
          mileage: s.mileage ? s.mileage : 0,
          total_price: s.total_price,
          base_carriage: s.baseCarriage,
          station_servicefee: s.stationServiceFee,
          fuel_add_fee: s.fuelAddFee,
          compute_fee: s.computeFee,
          coolair_fee: s.coolairFee,
          health_fee: s.healthFee,
          other_fee: s.otherFee,
          toplimit_price: s.topLimitPrice,
          lowerlimit_price: s.lowerLimitPrice,
        }
      })
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.addPOST(priceArry)
          // api.copyadd({ envBusInfo: this.form, envBusPrices: priceArry }).then((res) => {
          //   if (res == true) {
          //     this.$emit('hide', true)
          //     this.showDialog = false
          //     this.$emit('hide')
          //     this.$message({
          //       message: '添加成功',
          //       type: 'success',
          //     })
          //   }
          // })
        } else {
          this.$message({
            message: '请把内容填写完整',
            type: 'warning',
          })
          return false
        }
      })
    },
    addPOST(p) {
      let data = {
        envBusInfo: this.form,
        envBusPrices: p,
      }
      api.copyadd(data).then((res) => {
        if (res == true) {
          this.$emit('hide', true)
          this.showDialog = false
          this.$emit('hide')
          this.$message({
            message: '添加成功',
            type: 'success',
          })
        }
      })
    },
    isHide() {
      this.dialog = false
    },
    Times(k) {
      this.times = this.formatDate(k)
    },
    // 日期格式化
    formatDate(date) {
      //设置时间转换格式
      var time = new Date(date)
      var y = time.getFullYear() //获取年
      var m = time.getMonth() + 1 //获取月
      m = m < 10 ? '0' + m : m //判断月是否大于10
      var d = time.getDate() //获取日
      d = d < 10 ? '0' + d : d //判断日期是否大10
      return y + '-' + m + '-' + d //返回时间格式
    },
  },
}
</script>
<style>
.Dh_frame.el-input.is-disabled .el-input__inner {
  border: none;
  color: #000;
}
</style>
